#pragma once
#include <math.h>

//!	Andrea Mugnaini's MathManager
class MathManager
{
public:	
	static bool isDivisible(const int& dividend, const int& divisor) 
	{
		return (dividend % divisor == 0);
	}
	
	// Finds the integer square root of a positive number of any type
	template <typename type>
	static type intSqrt (type remainder)
	{
		if (remainder < 0) // if type is unsigned this will be ignored = no runtime
			return 0; // negative number ERROR

		type place = (type)1 << (sizeof (type) * 8 - 2); // calculated by precompiler = same runtime as: place = 0x40000000
		while (place > remainder)
			place /= 4; // optimized by complier as place >>= 2

		type root = 0;
		while (place)
		{
			if (remainder >= root+place)
			{
				remainder -= root+place;
				root += place * 2;
			}
			root /= 2;
			place /= 4;
		}
		return root;
	}

	static int asciiToInt(const char& c)
	{
		return static_cast<int>(c) - 48;
	}

	static int my_pow(const int& number, const int& p)
	{
		int tot = 1;
		for (int i=0;i < p;++i)
			tot *= number;
		return tot;
	}
};
